//
//  ChatListTitleView.swift
//  imprint
//
//  Created by 小柠檬🍋 on 2025/9/7.
//

import SwiftUI

struct ChatFunctionItemView: View {
    @State var bean: ChatFunctionBean
    
    var body: some View {
        HStack(alignment: .top) {
            VStack(alignment:.leading,spacing:2) {
                Text(bean.title)
                    .font(.system(size: 16, weight: .medium))
                    .foregroundColor(.bgNormalText)
                    .lineLimit(1)
                    .padding(.top, 12)
                if (bean.description).isEmpty == false {
                    Text(bean.description)
                        .font(.system(size: 12, weight: .medium))
                        .foregroundColor(.bgNormalText4)
                        .lineLimit(2)
                }
            }
            Spacer(minLength: 1)
            HStack{
                Image(bean.resource)
                    .resizable()
                    .padding(bean.padding)
            }.frame(width: 40, height: 40)
                .background(themeManager.themeColor)
                .clipShape(Circle())
                .padding(.top, 10)
            
        }
        .padding(.leading, 15)
        .padding(.trailing, 10)
        .padding(.bottom, 12)
        .frame(maxWidth: .infinity, minHeight: 85,alignment: .top)  // 关键：让VStack宽度充满父容器
        .background(.bgItem)
        .clipShape(RoundedRectangle(cornerRadius: 10))
        .contentShape(Rectangle())
        .onTapGesture {
            switch bean.type {
            case .TYPE_LETTER :
                pathManager.jump(type: JumpType.WEEKLY_LETTER)
            case .TYPE_CALL:
                pathManager.jump(type: JumpType.CALL_HISTORY)
//            case .TYPE_MAP:
//            case .TYPE_MIGRATE:
            case .TYPE_MEMORY:
                pathManager.jump(type: JumpType.AI_SET_VIEW, data: AiSetView.FromType.FROM_MEMORY)
            case .TYPE_AI:
                pathManager.jump(type: JumpType.AI_SET_VIEW, data: AiSetView.FromType.FROM_AI)
            case .TYPE_VOICE:
                pathManager.jump(type: JumpType.AI_SET_VIEW, data: AiSetView.FromType.FROM_VOICE)
            case .TYPE_CHAT:
                pathManager.jump(type: JumpType.AI_SET_VIEW, data: AiSetView.FromType.FROM_CHAT)
//            case .TYPE_INSTRUCTION:
//                pathManager.jump(type: JumpType.AI_SET_VIEW,data: AiSetView.FromType.FROM_INSTRUCTION)
            case .TYPE_ACT:
                pathManager.jump(type: JumpType.AI_SET_VIEW, data: AiSetView.FromType.FROM_ACT)
            case .TYPE_AI_CUSTOM:
                pathManager.jump(type: JumpType.AI_CUSTOM)
            case .TYPE_DIARY:
                pathManager.jump(type: JumpType.AI_SET_VIEW, data: AiSetView.FromType.FROM_DIARY)
            }
        }
    }
}

#Preview {
    ChatFunctionItemView(bean: ChatFunctionBean(type:.TYPE_LETTER ,title: "已选择心灵角色", description: "已选定的角色才能触发日记回复，来电，来信",resource:.homeIconCall, padding: 3))
}
